package com.leyou.auth.web;

import com.leyou.auth.service.UserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <h3>leyou-project</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-06-06 15:07
 **/
@RestController
@RequestMapping("/user")
public class UserAuthController {

@Autowired
private UserAuthService service;

    @PostMapping("/login")
    public ResponseEntity<Void>  login(@RequestParam("username")String username,
                                         @RequestParam("password")String password,
                                         HttpServletResponse response) {
       service.login(username, password, response);
        return ResponseEntity.noContent().build();
    }

    @GetMapping("/verify")
    public ResponseEntity<String> verify(HttpServletRequest request) {
        String username = service.verify(request);

        return ResponseEntity.ok(username);
    }
    @PostMapping("/logout")
    public ResponseEntity<Void> logout(HttpServletRequest request, HttpServletResponse response){
        service.logout(request, response);
        return ResponseEntity.noContent().build();

    }


}
